<template>
	<!-- components/my-coupons/my-coupons.wxml -->
	<scroll-view scroll-y="true" class="my-coupons">
		<coupon-list v-if="!showNull" :list="couponList" :btnType="type" @getCouPon="getCouPonFun"></coupon-list>
		<view v-else class="column-center" style="padding-top: 200rpx">
			<image class="img-null" src="/static/images/coupon_null.png"></image>
			<text class="muted">暂无优惠券～</text>
		</view>
	</scroll-view>
</template>

<script>
	import {
		getMyCoupon
	} from '../../api/user';

	export default {
		data() {
			return {
				couponList: [],
				showNull: false
			};
		},

		props: {
			type: {
				type: Number,
				default: 0
			},
		},
		beforeMount: function() {
			this.getMyCouponFun();
		},
		methods: {
			getCouPonFun(data) {
				this.$emit('getCouPon', data);
			},
			getMyCouponFun() {
				const {
					type,
				} = this;
				getMyCoupon({
					type: type === 2 ? 0 : type,
					pageSize: 60,
				}).then(({
					code,
					data,
					msg
				}) => {
					if (code == 200) {
						this.$emit('getnum', {
							detail: data.count
						});
						if (data.count <= 0) {
							this.showNull = true;
							return;
						}
						this.couponList = data.lists;

					}
				});
			}

		}
	};
</script>
<style>
	/* components/my-coupons/my-coupons.wxss */
	.my-coupons {
		min-height: calc(100% - 80rpx);
		height: 100%;
	}
</style>
